home *** CD-ROM | disk | FTP | other *** search
- #include "assert.h"
- #include "trace.h"
- #include "symbols.h"
- #include "allocate.h"
-
- typedef enum { DISymbol, DIStart, DIEnd, DIVector } DITag;
- #define StackDepth() (sstack ? sstack->depth : 1)
-
- typedef struct sSymbolInfo {
- DITag tag;
- int label;
- Symbol sym;
- int depth;
- struct sSymbolInfo *stack, *list;
- } SymbolInfo;
-
- extern int nextLabelNumber;
- extern char *addressToString();
- static SymbolInfo *sroot = NULL, *sstack = NULL;
- static unsigned int currentDepth = 0;
-
- debugStart()
- {
- /* lose stuff */
- sstack = NULL;
- sroot = NULL;
- currentDepth = 0;
- TRACE0(debuginfo, 2, "Starting");
- }
-
- dumpem(s)
- register SymbolInfo *s;
- {
- char *str;
- int size;
- AllocateKind kind;
- NodePtr ct;
- OID id;
-
- if (s->list) dumpem(s->list);
- switch (s->tag) {
- case DIStart:
- TRACE0(debuginfo, 5, "Start scope");
- writeWord(98);
- emit("\t.long\tL_%d - L_beginCDA\n", s->label);
- break;
- case DIEnd:
- TRACE0(debuginfo, 5, "End scope");
- writeWord(99);
- emit("\t.long\tL_%d - L_beginCDA\n", s->label);
- break;
- case DISymbol:
- TRACE1(debuginfo, 5, "Symbol %s", s->sym->itsName);
- writeWord(100);
- writeWord(strlen(s->sym->itsName));
- writeStringData(s->sym->itsName);
- figureSizeAndKind(s->sym, &size, &kind);
- writeWord(size);
- if (size == 4) {
- extern NodePtr getCTInfo();
- ct = getCTInfo(s->sym);
- if (ct == NULL) {
- Comment("Can't find ct info for %s", s->sym->itsName);
- TRACE1(emit, 0, "Can't find ct info for %s", s->sym->itsName);
- ct = s->sym->value.ATinfo;
- id = OIDOf(ct);
- } else {
- id = ct->b.oblit.codeOID;
- }
- } else {
- ct = s->sym->value.ATinfo;
- id = OIDOf(ct);
- }
- writeHex(id);
- str = addressToString(s->sym->v.address);
- writeWord(strlen(str));
- writeStringData(str);
- break;
- case DIVector:
- TRACE0(debuginfo, 5, "This thing is a vector");
- writeWord(101);
- writeWord(s->label); /* Really size */
- writeHex((OID)s->sym); /* Really range AT */
- break;
- default:
- assert(0);
- break;
- }
- free((char *) s);
- }
-
- debugDump()
- {
- /* dump it */
- TRACE0(debuginfo, 2, "Ending");
- emit("L_debugInfoMap:\n");
- if (sroot) dumpem(sroot);
- writeWord(0);
- sroot = sstack = NULL;
- currentDepth = 0;
- }
-
- static doABegin(tag)
- DITag tag;
- {
- register SymbolInfo *si;
- si = (SymbolInfo *) malloc(sizeof(SymbolInfo));
- si->tag = tag;
- si->label = nextLabelNumber++;
- emit("L_%d:\n", si->label);
- si->list = sroot;
- sroot = si;
- }
-
- debugScope(goingin)
- int goingin;
- {
- SymbolInfo *s;
- if (goingin) {
- currentDepth ++;
- TRACE1(debuginfo, 6, "Begin scope to %d", currentDepth);
- if (currentDepth == 1) doABegin(DIStart);
- } else {
- if (currentDepth == 1 || sstack && sstack->depth == currentDepth) {
- TRACE1(debuginfo, 4, "Back to depth %d", currentDepth-1);
- /* write the stab */
- doABegin(DIEnd);
- }
- while (sstack && sstack->depth == currentDepth) {
- TRACE1(debuginfo, 5, "losing %s", sstack->sym->itsName);
- sstack = sstack->stack;
- }
- currentDepth--;
- TRACE1(debuginfo, 6, "End scope, back to %d", currentDepth);
- }
- }
-
- debugSymbol(s)
- Symbol s;
- {
- SymbolInfo *si;
-
- if (StackDepth() < currentDepth) {
- TRACE1(debuginfo, 4, "Up to depth %d", currentDepth);
- /* write the stabs */
- doABegin(DIStart);
- }
- si = (SymbolInfo *) malloc(sizeof(SymbolInfo));
- si->tag = DISymbol;
- si->depth = currentDepth;
- si->sym = s;
- TRACE1(debuginfo, 5, "Adding %s", s->itsName);
- si->stack = sstack;
- sstack = si;
- si->list = sroot;
- sroot = si;
- }
-
- debugVector(ofAT, size)
- OID ofAT;
- int size;
- {
- SymbolInfo *s;
- TRACE0(debuginfo, 4, "This guy is a vector");
- if (StackDepth() < currentDepth) {
- TRACE1(debuginfo, 4, "Up to depth %d", currentDepth);
- /* write the stabs */
- doABegin(DIStart);
- }
- /* write the stab */
- s = (SymbolInfo *) malloc(sizeof(SymbolInfo));
- s->tag = DIVector;
- s->depth = currentDepth;
- s->label = size;
- s->sym = (Symbol) ofAT;
- s->stack = sstack;
- sstack = s;
- s->list = sroot;
- sroot = s;
- }
-